package cn.mrlong.contactutils;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView ryContacts, ryCall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initRy();
    }

    private void initRy() {
        ryContacts = findViewById(R.id.ry_contacts);
        ryCall = findViewById(R.id.ry_call);

        ryContacts.setLayoutManager(new LinearLayoutManager(MainActivity.this));
        ContactsAdapter contactsAdapter = new ContactsAdapter(MainActivity.this, new ArrayList<ContactInfo>(), new RecyclerViewItemOnClick() {
            @Override
            public void onClick(int postion) {

            }
        });
        ryContacts.setAdapter(contactsAdapter);
        List<ContactInfo> contactInfoList = ContactsUtils.readAll(MainActivity.this, new PermissionCallBack() {
            @Override
            public void permissionErr(String permission) {
                Toast.makeText(MainActivity.this, "权限：" + permission + "获取失败！", Toast.LENGTH_SHORT).show();
            }
        });
        if (contactInfoList.size() > 0) {
            contactsAdapter.addDatas(contactInfoList);
        }

        ryCall.setLayoutManager(new LinearLayoutManager(MainActivity.this));
        CallAdapter callAdapter = new CallAdapter(MainActivity.this, new ArrayList<CallInfo>(), new RecyclerViewItemOnClick() {
            @Override
            public void onClick(int postion) {

            }
        });
        ryCall.setAdapter(callAdapter);
        List<CallInfo> callInfoList = CallInfoService.getCallInfos(MainActivity.this, new PermissionCallBack() {
            @Override
            public void permissionErr(String permission) {
                Toast.makeText(MainActivity.this, "权限：" + permission + "获取失败！", Toast.LENGTH_SHORT).show();
            }
        });
        if (callInfoList.size() > 0) {
            callAdapter.addDatas(callInfoList);
        }
    }
}
